package com.twu.biblioteca;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MenuAlert {
    private int MIN_MENU_OPTION = 1;
    private String menuoptions[] = {"<press 1> List books available.","<press 2> List movies available.","<press 3> Reserve book.","<press 4> Check membership."};

    public String getWelcomeMessage() {
        return "--------------------------------------\t\tWelcome to Biblioteca\t\t------------------------------";
    }

    public String showMenuOptions() {
        String options = "";
        for(String option : menuoptions){
           options+= option+"\n";
        }
        return options;
    }

    public boolean checkIdValid(int option) {
        return option >= MIN_MENU_OPTION && option <= menuoptions.length;
    }


    public int getUserOption() throws Exception{
        int selected_option = Integer.parseInt(getConsoleInput());
        if(checkIdValid(selected_option) == false){
           throw new Exception("Select a valid option!!");
        }
        return selected_option;
    }

    public String getConsoleInput() {
        String inputValue = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            try {
                   inputValue = br.readLine();
                 }
            catch (IOException e) {
                    e.printStackTrace();
        }
        return inputValue;
    }
}
